<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>

<body>
    <div id="root">
        <h2>监听属性的基本使用</h2>
        <h3>内容：{{msg}}</h3>
        修改内容：<input type="text" v-model="msg">
        <button @click="count++">累加器:{{count}}</button>
        <p>计算属性：doubleCount{{doubleCount}}</p>
    </div>
    <script>
        Vue.config.productionTip = false;	 // 阻止 Vue在启动时生成生产提示
        
        const vm = new Vue({
            el: "#root", // 挂载的容器
            data() { // 数据
                return {
                    msg: "",
                    count: 2,
                }
            },
            computed:{
                doubleCount(){
                    return this.count*2
                }
            },
            watch:{
                msg(newVal,oldVal){
                    console.log(newVal,'最新值',oldVal,'旧的值')
                    console.log('msg修改了')
                },
                doubleCount() {
                  console.log("重新计算了count");
                },
            }
        })
</script>
</body>

</html>